package leetcode.top100;

import org.junit.Test;

import java.util.Stack;

/**
 * @author ：zsy
 * @date ：Created 2022/11/10 9:37 PM
 * @description：
 */
public class _020_有效的括号 {
    @Test
    public void test() {
        System.out.println(new Solution().isValid("{{[[()]]]}}"));
    }

    class Solution {
        public boolean isValid(String s) {
            Stack<Character> stack = new Stack<>();
            for (int i = 0; i < s.length(); i++) {
                char ch = s.charAt(i);
                switch (ch) {
                    case '(' : {
                        stack.push(')');
                        continue;
                    }
                    case '{' : {
                        stack.push('}');
                        continue;
                    }
                    case '[' : {
                        stack.push(']');
                        continue;
                    }
                }
                if (stack.isEmpty() || stack.peek() != ch) return false;
                stack.pop();
            }
            return stack.isEmpty();
        }
    }
}
